/*******************************************************************
 *
 * Copyright (C), 2021-2022, LS, All rights reserved.
 *
 * Author      :
 * Create Time : 2021-10-21
 * Version     : v0.1
 * Description : 
 *******************************************************************/
#ifndef  _SLBOOT_H_
#define  _SLBOOT_H_

/*----------------------------Head file----------------------------*/
#include "stdint.h"

/*----------------------------macro file---------------------------*/
#define OTAF_SECTOR_SIZE            0x1000
#define OTAF_PARTITION_NUM_MAX      32

//(CFG_FLASH >= 512 && USE_FCT==0 && CFG_OTA_BANK_MODE==OTA_SINGLE_BANK)
#define OTAF_BASE_ADDR				0x11000000

#define APP_IMG_MAX_SIZE		    (1024*144)

#define OTAF_1st_BOOTINFO_ADDR		0x11002000  //4k bytes
#define OTAF_2nd_BOOTINFO_ADDR		0x11003000  //4k bytes

#define BOOTLOADER_BIN_ADDR		    0x11004000  //4k bytes
#define BOOTLOADER_BIN_MAX_SIZE     (1024*25)

#define APP_BANK_BIN_ADDR			0x11011000  //144K bytes
#define APP_TEMP_BIN_ADDR			(APP_BANK_BIN_ADDR + APP_IMG_MAX_SIZE)  //144K bytes

#define OTAF_2nd_BOOT_FAST_BOOT     0x11003ff0  //bypass 2nd boot crc check for fast boot

#define SLB_EXCH_AREA_BASE          APP_TEMP_BIN_ADDR
#define SLB_FLASH_FW_BASE           (SLB_EXCH_AREA_BASE)
#define SLB_FLASH_FW_PART_NUM       (SLB_EXCH_AREA_BASE+4)

#define SLB_FLASH_FW_PART_FADDR(n)  (SLB_EXCH_AREA_BASE + 0x10 + 0x10*(n))
#define SLB_FLASH_FW_PART_RADDR(n)  (SLB_EXCH_AREA_BASE + 0x14 + 0x10*(n))
#define SLB_FLASH_FW_PART_SIZE(n)   (SLB_EXCH_AREA_BASE + 0x18 + 0x10*(n))
#define SLB_FLASH_FW_PART_CHKSUM(n) (SLB_EXCH_AREA_BASE + 0x1c + 0x10*(n))
#define SLB_FLASH_PART_DATA_BASE    (SLB_EXCH_AREA_BASE + 0x1000)


#define __APP_RUN_ADDR__        (0x1FFF1838)

#define OTAF_PARTITION_NUM		2

#define OTA_MAGIC_CODE          0x32af08cb  //random data
#define OTA_FAST_BOOT_MAGIC     0xa5a55a5a  //random data

/*----------------------------type define--------------------------*/

enum
{
    OTAF_SINGLE_BANK = 0,
    OTAF_DUAL_BANK_0  = 1,
    OTAF_DUAL_BANK_1  = 2
};


typedef enum {
	ERR_NONE = 0,			//none error
	ERR_FATAL,				//fatal error
	ERR_INTERNAL,			//internal error
	ERR_UNKNOWN,			//unknown error
	ERR_NO_MEM,				//no memory for operation
	ERR_NOT_FOUND,			//not found
	ERR_NOT_SUPPORTED,		//not supported
	ERR_INVALID_PARAM,		//invalid parameters
	ERR_INVALID_STATE,		//invalid state
	ERR_INVALID_LENGTH,		//invalid length
	ERR_INVALID_FLAGS,		//invalid flag
	ERR_INVALID_ADDR,		//invalid address
	ERR_BUSY,				//busy
	ERR_NOT_REGISTED,		//not registed
	ERR_NOT_IMPLEMENTED,	//Function is not implemented now
	ERR_FORBIDDEN,			//forbidden
	ERR_CHECK,				//check error
	ERR_TIMEOUT,			//timeout
    ERR_DATA_ALIGN,         //Data alignment is not correct
    ERR_BLE_NOT_READY,      //BLE not ready error
    ERR_FLASH,              //falsh operation error
}ErrCode_t;

/*----------------------------var define---------------------------*/

/*-------------------------func declaration------------------------*/
extern void boot_app(void);

/*-----------------------------------------------------------------*/


#endif
